package cool.tenyears.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cool.tenyears.common.constant.UserConstant;
import cool.tenyears.common.method.UserMethod;
import cool.tenyears.domain.User;
import cool.tenyears.mapper.UserMapper;
import cool.tenyears.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author tenyears
 * @Description TODO
 * @Date 2021/6/16 21:05
 */

@Service
@RequiredArgsConstructor
@Slf4j
public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;

    @Override
    public User getById(String userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public User getByLoginName(String loginName) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery()
                .eq(User::getLoginUser, loginName)
                .eq(User::getDeleted, UserConstant.USER_NO_DELETED_0));
    }

    @Override
    public List<User> list(User user) {
        return userMapper.selectList(Wrappers.emptyWrapper());
    }

    @Override
    public int add(User user) {
        // TODO: 2021/6/17 1、校验登录名、手机号码、邮箱唯一
        // System.out.println("用户密码=" + user.getPassword());
        // 2、生成密码盐和加密密码
        UserMethod.setPwd(user);
        return userMapper.insert(user);
    }
}




